//
//  BrandCell.m
//  Pacific_Computer
//
//  Created by dlios on 14-12-18.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "BrandCell.h"
#import "UIImageView+WebCache.h"

@implementation BrandCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [ super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.brandLabel = [[UILabel alloc] init];
        self.brandLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.brandLabel];
        [_brandLabel release];
        
        self.logoImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.logoImage];
        [_logoImage release];
        
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.logoImage.frame = CGRectMake(self.contentView.bounds.size.width * 7.01 / 100, self.contentView.bounds.size.height * 28.57 / 100, self.contentView.bounds.size.width * 17.54 / 100, self.contentView.bounds.size.height * 42.85 / 100);
    
    self.brandLabel.frame = CGRectMake(self.contentView.bounds.size.width * 31.57 / 100, self.contentView.bounds.size.height * 2 / 7, self.contentView.bounds.size.width * 42.1 / 100, self.contentView.bounds.size.height * 3 / 7);
}


- (void)setProduct:(Product *)product
{
    if (_product != product) {
        [_product release];
        _product = [product retain];
    }
    
    _brandLabel.text = product.name;
    
    if (product.logo == nil) {
        self.logoImage.frame = CGRectMake(0, 0, 0.1, 0.1);
        self.brandLabel.frame = CGRectMake(20, 20, 120, 30);
        
    }else
    {
        NSString *str = product.logo;
        str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:str];
        [_logoImage setImageWithURL:url];
    }
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
